import getIn from '../yali-sdk/utils/getIn';
import { getYaliLiveSetting, getYaliUserInfo } from './checkAuth';
const liveroom = require('../yali-sdk/business/live/lib/liveroom.js');

// 腾讯云RoomService后台请求域名
const roomServiceUrl = 'https://room.qcloud.com';
const getlogininfo = (options) => {
    getYaliUserInfo().then((user) => {
        // 直播加密因子采用openid
        const openid = getIn(user, ['open_id']);
        const userName = getIn(user, ['name']);
        getYaliLiveSetting(openid).then((ret) => {
            console.log('#yali#log#获取直播ret', ret);
            ret.serverDomain = `${roomServiceUrl}/weapp/${options.type}/`;
            ret.userName = userName;
            ret.userID = openid;
            switch (options.type) {
                case 'live_room': {
                    liveroom.login({
                        data: ret,
                        success: options.success,
                        fail: options.fail,
                    });
                    break;
                }
                case 'logout': { // 注销
                    liveroom.logout();
                    break;
                }
                default: break;
            }
        }, () => console.log('#yali#log#getYaliUserInfo error'));
    }, () => { console.log('#yali#log#getYaliUserInfo error'); });
};
export default getlogininfo;
